#!/bin/bash
set -e

. /etc/parallelcluster/cfnconfig

# Notify compute is ready
instance_id_url="http://169.254.169.254/latest/meta-data/instance-id"
instance_id=$(curl --retry 3 --retry-delay 0 --silent --fail ${instance_id_url})
local_hostname_url="http://169.254.169.254/latest/meta-data/local-hostname"
local_hostname=$(curl --retry 3 --retry-delay 0 --silent --fail ${local_hostname_url})
<%= node['cfncluster']['cookbook_virtualenv_path'] %>/bin/aws --region ${cfn_region} sqs send-message --queue-url ${cfn_sqs_queue} --message-body '{"Type" : "Notification", "Message" : "{\"StatusCode\":\"Complete\",\"Description\":\"Succesfully launched '${instance_id}'\",\"Event\":\"parallelcluster:COMPUTE_READY\",\"EC2InstanceId\":\"'${instance_id}'\",\"Slots\":\"'${cfn_instance_slots}'\",\"LocalHostname\":\"'${local_hostname}'\"}"}'
